<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 200px;
            height: 60px;
            margin: auto;
            margin-top: 180px;
            font-size: 30px;
            padding: 5px;
            /* border: 1px solid red; */
        }
        
        .box span {
            color: #fff;
            background: #000;
            padding: 5px;
        }
    </style>
</head>

<body>
    <div class="box">
        <span>00</span> :
        <span>00</span> :
        <span>00</span>
    </div>
    <script>
        var aSpan = document.querySelectorAll("span");
        // 获取时间函数
        // 参数：end_time最后时间
        setInterval(time_data, 1000);

        function time_data() {
            // 结束时间
            let d1 = +new Date('2021-8-26 20:00');
            // 获取时间戳
            let d2 = +new Date();
            // 时间差 秒数
            let time = (d1 - d2) / 1000;
            // return time;
            let s = Math.ceil(time % 60);
            console.log(s);
            let m = parseInt(time / 60) % 60;
            console.log(m);
            let h = parseInt(time / 60 / 60);
            console.log(h);
            let t = [h, m, s];
            for (let i = 0; i < aSpan.length; i++) {
                aSpan[i].innerHTML = addZero(t[i]);
            }
        }
        time_data(time_str);

        function addZero(num) {
            num = num < 10 ? '0' + num : num;
            return num;
        }
        // console.log(addZero(9));
    </script>
</body>

</html>